<?php
############## DIT STUK CODE ZORGT ERVOOR DAT JE ALS ADMIN INGELOGD MOET ZIJN OM DE PAGINA TE KUNNEN ZIEN ##############
    //Start de sessie
    session_start();

    //Load de benodigde bestanden
    require_once("includes/auth.php");
########################################################################################################################
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"  xmlns:v="urn:schemas-microsoft-com:vml">
<head>
  <title>Route</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  
    <script src=" http://maps.google.com/?file=api&amp;v=2&amp;key=ABQIAAAAMK3NR9S2l_KVSWnLRs21TxSkcpRDfObmwbr2LOuZPXcwYRLDFxQMeoge_C5iOQgHQrldPGhmCDxXHA"
      type="text/javascript"></script>
    <style type="text/css">
      body {
        font-family: Verdana, Arial, sans serif;
        font-size: 11px;
        margin: 2px;
      }
      table.directions th {
        background-color:#EEEEEE;
      }
      img {
        color: #000000;
      }
    </style>

<?php

		// Database connection
		include 'includes/connect.php';

             if(isset($_GET['id']) && is_numeric($_GET['id']))
                  {
                    // Geef de variabele $id de waarde van de id= parameter uit de URL mee
                      $id=$_GET['id'];
                 }
                  else
                  {
                        header("Location: index.php");
                  }

		                      // Retrieve all the data from the table
                      $query = "SELECT * FROM klant WHERE klantid=" . $id . " ";
                      // echo 'query is: ',$query;
                      $result = mysql_query($query) or die("the query returned an error: " . mysql_error());

                      while ($row = mysql_fetch_array($result)) {
                      $straat= $row['straatnaam'];
                      $huisno= $row['huisnummer'];
                      $plaats = $row['woonplaats'];
                      $amsterdam = 'Amsterdam';
					  }

?>
    <script type="text/javascript">

    var map;
    var gdir;
    var geocoder = null;
    var addressMarker;
	var adres = "<?php echo "$straat $huisno,$plaats"; ?>";


    function initialize() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "addoverlay", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);

        setDirections("G J de Jonghweg 4, Rotterdam", adres, "nl");
      }
    }
    
    function setDirections(fromAddress, toAddress, locale) {
      gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
    }

    function handleErrors(){
   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
     alert("Het adres is niet bekend bij Google Maps. Voer eventueel handmatig een nieuw adres in.\nError code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
   else alert("An unknown error occurred.");
    }

  function onGDirectionsLoad(){ 
   var poly = gdir.getPolyline();
   if (poly.getVertexCount() > 10000) {
     alert("This route has too many vertices");
     return;
   }
   var baseUrl = "http://maps.google.com/staticmap?";

   var params = [];
   var markersArray = [];
   markersArray.push(poly.getVertex(0).toUrlValue(5) + ",greena");
   markersArray.push(poly.getVertex(poly.getVertexCount()-1).toUrlValue(5) + ",greenb");
   params.push("markers=" + markersArray.join("|"));

   var polyParams = "rgba:0x0000FF80,weight:5|";
   var polyLatLngs = [];
   for (var j = 0; j < poly.getVertexCount(); j++) {
     polyLatLngs.push(poly.getVertex(j).lat().toFixed(5) + "," + poly.getVertex(j).lng().toFixed(5));
   }
   params.push("path=" + polyParams + polyLatLngs.join("|"));
   params.push("size=300x300");
   params.push("key=ABQIAAAAMK3NR9S2l_KVSWnLRs21TxSkcpRDfObmwbr2LOuZPXcwYRLDFxQMeoge_C5iOQgHQrldPGhmCDxXHA");

   baseUrl += params.join("&");

   var extraParams = [];
   extraParams.push("center=" + map.getCenter().lat().toFixed(6) + "," + map.getCenter().lng().toFixed(6));
   extraParams.push("zoom=" + map.getZoom());
   addImg(baseUrl + "&" + extraParams.join("&"), "staticMapOverviewIMG");

   var extraParams = [];
   extraParams.push("center=" + poly.getVertex(0).toUrlValue(5));
   extraParams.push("zoom=" + 15);
   addImg(baseUrl + "&" + extraParams.join("&"), "staticMapStartIMG");

   var extraParams = [];
   extraParams.push("center=" + poly.getVertex(poly.getVertexCount()-1).toUrlValue(5));
   extraParams.push("zoom=" + 15);
   addImg(baseUrl + "&" + extraParams.join("&"), "staticMapEndIMG");
}

function addImg(url, id) {
 var img = document.createElement("img");
 img.src = url;
 document.getElementById(id).innerHTML = "";
 document.getElementById(id).appendChild(img);
}

    </script>


</head>

<body onload="initialize()" onunload="GUnload()">   
        <form action="#" onsubmit="setDirections(this.from.value, this.to.value, this.locale.value); return false">

  <table>

   <tr><th align="right">Van&nbsp;</th>

   <td><input type="text" size="25" id="fromAddress" name="from"
     value="G J de Jonghweg 4, Rotterdam"/></td>
     <th align="right">&nbsp;&nbsp;Naar:&nbsp;</th>
   <td align="right"><input type="text" size="25" id="toAddress" name="to"
     value="<?php echo "$straat $huisno,$plaats"; ?>" /></td></tr>
     <input type ="hidden" name="locale" value="nl">
   <!--<tr><th>Language:&nbsp;</th>
   <td colspan="3"><select id="locale" name="locale">

    <option value="nl" selected>English</option>
    <option value="fr">French</option>

    <option value="de">German</option>
    <option value="ja">Japanese</option>
    <option value="es">Spanish</option>
	<option value="nl">Dutch</option>
    </select> 
    -->

    <input name="submit" type="submit" value="Bereken" />
      </table>

    
  </form>
<a href="javascript:window.print()">Print!</a>
    <br/>
        <table class="directions">
    <tr><th>Beschrijving</th><th>Kaart</th></tr>

    <tr>
    <td valign="top"><div id="directions" style="width: 275px"></div></td>
    <td valign="top"><div id="map_canvas" style="width: 310px; height: 400px"></div></td>

    </tr>
    </table> 


</body>
</html>